﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FuckData.Model;
using FuckCore.DAO;

namespace FuckData.DAO
{
    public class AccountDAO:BaseDAO<GoEasyEntities,tbl_Account>
    {
        /// <summary>
        /// Create by DucND
        /// Datecreate 17/01/2014
        /// Check login of user
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public tbl_Account CheckLogin(string UserName, string Password)
        {
            var Result = from acc in ObjectContext.tbl_Account
                         where acc.Password.ToUpper() == Password.ToUpper() && acc.UserName.ToUpper() == UserName.ToUpper()
                         && acc.Status == 1
                         select acc;
            return Result.Count()>0 ? Result.FirstOrDefault() : null;
        }

        /// <summary>
        /// Check username is exist
        /// </summary>
        /// <param name="Username"></param>
        /// <returns></returns>
        public tbl_Account CheckUsername(string Username)
        {
            var Result = from Acc in ObjectContext.tbl_Account
                         where Acc.UserName.ToUpper() == Username.ToUpper()
                         select Acc;
            return Result.Count() > 0 ? Result.FirstOrDefault() : null;

        }

        /// <summary>
        /// Check email is exist
        /// </summary>
        /// <param name="Username"></param>
        /// <returns></returns>
        public tbl_Account CheckEmail(string Email)
        {
            var Result = from Acc in ObjectContext.tbl_Account
                         where Acc.Email.ToUpper() == Email.ToUpper()
                         select Acc;
            return Result.Count() > 0 ? Result.FirstOrDefault() : null;

        }

        public tbl_Account GetActiveByID(long ID)
        {
            var Result = from Acc in ObjectContext.tbl_Account
                         where Acc.Status == 1
                         && Acc.ID == ID
                         select Acc;
            return Result.Count() > 0 ? Result.FirstOrDefault() : null;
        }
    }
}
